<template>
  <div id="container" style="height: 400px">

  </div>
</template>

<script>
  import { createWs, sheet2blob, openDownloadDialog } from "../../utils/exportExcel"

  export default {
    name: "exportExcel",
    components: {

    },
    data() {
      return {
        res_data : [
          {'ctime':'2020-01-12','new_count':'12','online_count':'12','total_count':'12'},
          {'ctime':'2020-01-13','new_count':'12','online_count':'12','total_count':'13'},
          {'ctime':'2020-01-14','new_count':'12','online_count':'12','total_count':'14'},
          {'ctime':'2020-01-15','new_count':'12','online_count':'12','total_count':'15'},
        ]
      }
    },
    methods: {
      toExcel(){
        const titles = {
          ctime: '注册时间',
          new_count: '注册总人数',
          online_count: '在线总人数',
          total_count: '累计总人数'
        }
        const fields = ['ctime', 'new_count', 'online_count', 'total_count']
        const ws = createWs(
                this.res_data, // 后台返回的json数据
                fields,
                titles
        )
        openDownloadDialog(sheet2blob(ws), '权利人分析.xlsx');
      },

    },
    mounted() {
      this.toExcel()
    }
  }
</script>

<style scoped>

</style>
